package za.org.jcicada.katcp;

/**
 * SensorBoolean.java
 *
 * @author Adrianna Pinska
 *
 * Created on October 27, 2008, 18:21
 */

import za.org.jcicada.katcp.ISensor;
import za.org.jcicada.katcp.ISensorValue;
import za.org.jcicada.katcp.SensorBase;
import za.org.jcicada.katcp.SensorValueBase;

/**
 * A base class for KAT device boolean sensors.
 */
public class SensorBoolean extends SensorBase {

    /**
     * A class for Boolean sensor values.
     */
    static public class BooleanValue extends SensorValueBase {

        /**
         * This Boolean sensor's value.
         */
        protected boolean value;

        /**
         * Constructs a BooleanValue object.
         */
        public BooleanValue(){
            super();
            value = false;
        }

        /**
         * Constructs a BooleanValue object.
         *
         * @param timestamp  When the sensor value was recorded.
         * @param status     The sensor status when the value was recorded.
         * @param value      The sensor value.
         */
        public BooleanValue(long timestamp, ISensorValue.Status status, boolean value){
            super(timestamp, status);
            this.value = value;
        }

        /**
         * Get the value.
         *
         * @return  True or false.
         */
        public boolean getValue() {
            return value;
        }
    }

    /**
     * Constructs a SensorBoolean object.
     *
     * @param name         The sensor name.
     * @param description  A description of the sensor.
     * @param units        The units of the sensor value.
     */
    public SensorBoolean(String name, String description, String units) {
        super(name, ISensor.Type.BOOLEAN, new BooleanValue(), description, units, new String [0]);
    } 

    // ISensor Methods

    /**
     * Format a boolean sensor value.
     *
     * @param value  Sensor value to format.
     * @return  The value formatted as a string.
     */
    public String formatValue(ISensorValue value) {
        boolean bvalue = ((BooleanValue) value).getValue();
        return bvalue ? "1" : "0";
    }

}
